<?php
include_once "lib/config.php";
include_once "header.php";
if(isset($_SESSION['msg_success']) && $_SESSION['msg_success']!="")
{
	$msg_success=$_SESSION['msg_success'];
	unset($_SESSION['msg_success']);
}

if(isset($_SESSION['msg_error']) && $_SESSION['msg_error']!="")
{
	$msg_error=$_SESSION['msg_error'];
	unset($_SESSION['msg_error']);
}

################################ Profile Pic Upload Code ###################################
if(isset($_FILES['profile_photo']['name']) && $_FILES['profile_photo']['name']!="")
{
	if(isset($selecttrainermngr[0]['profile_photo']) && $selecttrainermngr[0]['profile_photo']!=Null){
		 if(file_exists($selecttrainermngr[0]['profile_photo']))
		 {
			$new_path=	$selecttrainermngr[0]['profile_photo'];
		 }  
		 else
		 {
			$new_path="";
		 }
	}
	if($_FILES['profile_photo']['name']!="")
    {
        include_once "thumb.php";
        if($_FILES['profile_photo']['type']=="image/jpeg" || $_FILES['profile_photo']['type']=="image/gif" || $_FILES['profile_photo']['type']=="image/png" || $_FILES['profile_photo']['type']=="image/jpg" || $_FILES['profile_photo']['type']=="image/JPEG" || $_FILES['profile_photo']['type']=="image/GIF" || $_FILES['profile_photo']['type']=="image/PNG" || $_FILES['profile_photo']['type']=="image/JPG")
        {
            list($width, $height) = getimagesize($_FILES['profile_photo']["tmp_name"]);
            $folder="../uploaded_files";
            $folder_val="uploaded_files/profile_photo";
            $exact_folder_val="uploaded_files/profile_photo/".$user_details[0]['id'];
            if(!file_exists($exact_folder_val))
            {
				mkdir($exact_folder_val,0777);
			}
            //$extension_arr=explode("/",$_FILES['profile_photo']['type']);
            //$extension=$extension_arr[1];
            
            $f=$_FILES['profile_photo']['name'];
            $path=$folder_val."/".$f;
            
            //$tem=$_FILES['profile_photo']['tmp_name'];
            
                    $target=$folder_val."/";
                    
                    $new_path=$exact_folder_val."/".$_FILES['profile_photo']['name'];
                    if(file_exists($new_path))
                    {
						unlink($new_path);
					}
                    
                    if($width>140 || $height>195)
                    {
                        $move= move_uploaded_file($_FILES['profile_photo']['tmp_name'], $new_path);
                        if($move)
                        {
                            createThumbsforProfiles_widthequal_Transparent($new_path,$new_path,140,195);
                        }
                        
                    }
                    else
                    {
                        $move= move_uploaded_file($_FILES['profile_photo']['tmp_name'], $new_path);
                    }
                	$msg_success="Profile image is uploaded successfully.";
        }
		else
		{
			$msg_error="Prfile image extension should be on of the (jpg,jpeg,png,gif)";
		}    
    }
    else
    {
		$msg_error="Image is not found!";
	}
    if($new_path!="")
    {
    	$arr_sanitize=$img_arr=array("profile_photo"=>$new_path);
		
        DB::updateData("users",$arr_sanitize,array("id"=>$user_details[0]['id']));
        
        $user_details=DB::fetch_array(DB::query("select users.*,user_type from users,user_types where users.type_id=user_types.id and users.id='".$user_details[0]['id']."' "));

	}
	else
	{
		$msg_error="Path cannot be empty for uploading profile pic.";
	}
	//echo "coming";
}

################################ Profile Pic Upload Code ends ###################################

?>
      
		<div class="container_12" id="main_div">
           <form action="" method="post" onsubmit="return valid();">
			<div class="float-left" style="padding-left:20px">
		        <a href="edit_profile.php" class="button">
		        	<span>Edit Profile</span>
		        </a>
		    </div><br><br/>
		    <div class="grid_6">
                <div class="module" >
                        <h2><span onclick="toggle_div('basic_body','basictoogleimg');"><img src="images/desc.gif" height="5px" id="basictoogleimg">&nbsp;&nbsp;Basic Information</span></h2>
                        
                        <div class="module-body" id="basic_body" >
                        	<div style="float:left;width:30%;text-align:center;">
    							<?php
    							$imagename=$unknown_image;
    							if(isset($user_details[0]['profile_photo']) && $user_details[0]['profile_photo']!=Null){
    								 if(file_exists($user_details[0]['profile_photo']))
    								 {
    									$imagename=	$user_details[0]['profile_photo'];
    								 }  
    								 else
    								 {
    									$imagename=$unknown_image;
    								 }
    							}	  
    							?>
    							<img src="<?php echo $imagename; ?>">
    							<br><a href="javascript:void(0)" onclick="return upload_profilepic();" title="Upload Profile Pic" >Edit Profile Image</a>
    						</div>
                            <div style="border:0px solid;float:left">
                            	<p>
                                    <strong>Full Name: </strong><?php echo trim($user_details[0]['full_name']); ?>
                                </p>
    							<p>    
                                    <strong>Employee Type: </strong><?php echo $user_details[0]['user_type']; ?>
                                </p>
    							<p>
    								<strong>Email ID: </strong><?php echo $user_details[0]['email_id']; ?>
    							</p>
    							
    							<p> 	
                                    <strong>Contact Number: </strong><?php if($user_details[0]['contact_number']!="")echo $user_details[0]['contact_number'];else echo "--"; ?>
                                </p>
                                <p>
    		                        <b>Gender:</b> <?php if(isset($user_details[0]['gender']) && $user_details[0]['gender']!=Null){ echo $user_details[0]['gender']; }else echo "NA"; ?>
    		                    </p> 
    							 <p>
    		                       <b>Date of Birth:</b> <?php if(isset($user_details[0]['dob']) && $user_details[0]['dob']!=0)echo date("d/m/Y",$user_details[0]['dob']);else echo "NA"; ?>
    		                    </p>
							     <p>     
                                    <strong>Address: </strong><?php if($user_details[0]['address']!="")echo $user_details[0]['address'];else echo "NA"; ?>
                                 </p>
    							  <p>
    		                        <b>City:</b> <?php if(isset($user_details[0]['city']) && $user_details[0]['city']!=Null)echo $user_details[0]['city']; else echo "NA-"; ?>
    		                    </p>
    		                    <p>
    		                        <b>State:</b> <?php if(isset($user_details[0]['state']) && $user_details[0]['state']!=Null)echo $user_details[0]['state']; else echo "NA"; ?>
    		                    </p>
                                <p>
    		                        <b>Country:</b> <?php if(isset($user_details[0]['country']) && $user_details[0]['country']!=Null)echo $user_details[0]['country']; else echo "NA"; ?>
    		                    </p>
    		                    <p>
    		                        <b>Pincode:</b> <?php if(isset($user_details[0]['pincode']) && $user_details[0]['pincode']!=Null)echo $user_details[0]['pincode'];else echo "NA"; ?>
    		                    </p>
                            </div>
							
                        </div>
                </div>
                <div style="clear:both;"></div>
            </div>
             <!-- End .grid_6 -->
            <div style="clear:both;"></div>
			
		 </form>    
        </div> <!-- End .container_12 -->
		
<?php include_once("footer.php"); ?>           
<?php
if(isset($msg_success) && $msg_success!="")
{
	$notymessage=$msg_success;
	$msgtype="success";
}
else if(isset($msg_error) && $msg_error!="")
{
	$msgtype="error";
	$notymessage=$msg_error;
}
else
{
	$msgtype="";
}
if($msgtype!="")
{
?>        
<script language="javascript">
	$(document).ready(function(){
		
		var options = $.parseJSON('{"text":"<?php echo $notymessage; ?>","layout":"top","type":"<?php echo $msgtype; ?>"}');
		noty(options);
		
	});
</script>  
<?php
}
?>